package org.hxzon.project.permissions;

import java.util.ArrayList;
import java.util.List;

public class BasePermissions<T, U> {
    private List<PermissionsChecker<T, U>> checkers = new ArrayList<PermissionsChecker<T, U>>();

    public void check(T target, U user) {
        for (PermissionsChecker<T, U> checker : checkers) {
            if (checker.check(target, user)) {
                return;
            }
        }
        throw new AuthenticationException("没有权限");
    }

    public void addChecker(PermissionsChecker<T, U> permissionsChecker) {
        checkers.add(permissionsChecker);
    }
}
